package com.aspose.cells.b.a.b.a.a;

import com.aspose.cells.a.e.zi;
import com.aspose.cells.b.a.b.zo;
import com.aspose.cells.b.a.b.a.zj;
import java.awt.Rectangle;
import java.awt.Shape;
import java.awt.geom.AffineTransform;
import java.awt.geom.FlatteningPathIterator;
import java.awt.geom.GeneralPath;
import java.awt.geom.IllegalPathStateException;
import java.awt.geom.PathIterator;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.awt.geom.Rectangle2D.Float;

public class za implements Shape, Cloneable {
   private byte[] a;
   private float[] b;
   private int c;
   private int d;
   private int e;
   private zj f;
   private GeneralPath g;

   public za() {
      this(1, 20, 20);
   }

   public za(Shape var1) {
      this(1, 20, 20);
      PathIterator var2 = var1.getPathIterator((AffineTransform)null);
      this.a(var2.getWindingRule());
      this.a(var2, false);
   }

   private za(int var1, int var2, int var3) {
      this.a = null;
      this.b = null;
      this.c = 0;
      this.d = 0;
      this.e = 0;
      this.f = null;
      this.g = null;
      this.a(var1);
      this.a(var2, var3);
   }

   private final GeneralPath m() {
      if (this.g == null) {
         PathIterator var1 = this.getPathIterator((AffineTransform)null);
         this.g = new GeneralPath();
         this.g.append(var1, false);
      }

      return this.g;
   }

   public final byte[] a() {
      return this.a;
   }

   public final float[] b() {
      return this.b;
   }

   public final int c() {
      return this.c;
   }

   public final int d() {
      return this.d;
   }

   public final boolean e() {
      return this.c() == 0 || (this.a()[this.c() - 1] & 4) != 0 || (this.a()[this.c() - 1] & 16) != 0;
   }

   public final int f() {
      return this.d() / 2;
   }

   public final zj g() {
      if (this.f == null) {
         this.f = this.o();
      }

      return this.f;
   }

   private final void n() {
      this.f = null;
      this.g = null;
   }

   private final zj o() {
      zj var1 = new zj();
      int var2 = this.f();

      int var3;
      for(var3 = 0; var3 < this.c(); ++var3) {
         if ((this.a()[var3] & 7) == 2) {
            ++var2;
         }
      }

      var1.a(new byte[var2]);
      var1.a(new zo[var2]);
      var3 = 0;
      int var4 = 0;
      int var5 = 0;

      for(int var8 = 0; var8 < this.c(); ++var8) {
         byte var9 = (byte)(this.a()[var8] & 7);
         byte var6 = (byte)((this.a()[var8] & 32) != 0 ? 32 : 0);
         switch(var9) {
         case 0:
            var1.b()[var3++] = zi.a(var6);
            var1.a()[var4++] = new zo(this.b()[var5++], this.b()[var5++]);
            break;
         case 1:
            var1.b()[var3++] = zi.a(1 | var6);
            var1.a()[var4++] = new zo(this.b()[var5++], this.b()[var5++]);
            break;
         case 2:
            float var10 = this.b()[var5 - 2];
            float var11 = this.b()[var5 - 1];
            float var12 = var10 + 0.0F * (this.b()[var5++] - var10);
            float var13 = var11 + 0.0F * (this.b()[var5++] - var11);
            float var14 = this.b()[var5++];
            float var15 = this.b()[var5++];
            float var16 = var12 + 0.0F * (var14 - var10);
            float var17 = var13 + 0.0F * (var15 - var11);
            var1.b()[var3++] = zi.a(3);
            var1.a()[var4++] = new zo(var12, var13);
            var1.b()[var3++] = zi.a(3);
            var1.a()[var4++] = new zo(var16, var17);
            var1.b()[var3++] = zi.a(3 | var6);
            var1.a()[var4++] = new zo(var14, var15);
            break;
         case 3:
            var1.b()[var3++] = zi.a(3);
            var1.a()[var4++] = new zo(this.b()[var5++], this.b()[var5++]);
            var1.b()[var3++] = zi.a(3);
            var1.a()[var4++] = new zo(this.b()[var5++], this.b()[var5++]);
            var1.b()[var3++] = zi.a(3 | var6);
            var1.a()[var4++] = new zo(this.b()[var5++], this.b()[var5++]);
            break;
         case 4:
            var1.b()[var3 - 1] = zi.a(var1.b()[var3 - 1] & 255 | 128 | var6);
         }
      }

      return var1;
   }

   public final void a(Shape var1) {
      this.a(var1, !this.e());
   }

   public final void a(PathIterator var1, boolean var2) {
      this.n();

      for(float[] var3 = new float[6]; !var1.isDone(); var2 = false) {
         switch(var1.currentSegment(var3)) {
         case 0:
            if (!var2 || this.c < 1 || this.d < 2) {
               this.b(var3[0], var3[1]);
               break;
            } else if (this.a[this.c - 1] != 4 && this.b[this.d - 2] == var3[0] && this.b[this.d - 1] == var3[1]) {
               break;
            }
         case 1:
            this.a(var3[0], var3[1]);
            break;
         case 2:
            this.a(var3[0], var3[1], var3[2], var3[3]);
            break;
         case 3:
            this.a(var3[0], var3[1], var3[2], var3[3], var3[4], var3[5]);
            break;
         case 4:
            this.h();
         }

         var1.next();
      }

   }

   public final void a(Shape var1, boolean var2) {
      PathIterator var3 = var1.getPathIterator((AffineTransform)null);
      this.a(var3, var2);
   }

   public Object clone() {
      za var1 = new za();
      var1.a = (byte[])com.aspose.cells.a.e.za.a(this.a);
      var1.b = (float[])com.aspose.cells.a.e.za.a(this.b);
      var1.e = this.e;
      var1.c = this.c;
      var1.d = this.d;
      return var1;
   }

   public final void h() {
      this.n();
      if (this.c == 0 || this.a[this.c - 1] != 4) {
         this.a(1, 0, true);
         this.a[this.c++] = 4;
      }

   }

   public boolean contains(double x, double y) {
      return this.m().contains(x, y);
   }

   public boolean contains(double x, double y, double w, double h) {
      return this.m().contains(x, y, w, h);
   }

   public boolean contains(Point2D p) {
      return this.contains(p.getX(), p.getY());
   }

   public boolean contains(Rectangle2D r) {
      return this.contains(r.getX(), r.getY(), r.getWidth(), r.getHeight());
   }

   public final void a(float var1, float var2, float var3, float var4, float var5, float var6) {
      this.n();
      this.a(1, 6, true);
      this.a[this.c++] = 3;
      this.b[this.d++] = var1;
      this.b[this.d++] = var2;
      this.b[this.d++] = var3;
      this.b[this.d++] = var4;
      this.b[this.d++] = var5;
      this.b[this.d++] = var6;
   }

   public Rectangle getBounds() {
      return this.getBounds2D().getBounds();
   }

   public Rectangle2D getBounds2D() {
      float var1 = 0.0F;
      float var2 = 0.0F;
      float var3 = 0.0F;
      float var4 = 0.0F;
      boolean var5 = false;
      float var6 = 0.0F;
      float var7 = 0.0F;
      int var9 = this.d;
      if (var9 > 0) {
         --var9;
         var2 = var4 = this.b[var9];
         --var9;
         var1 = var3 = this.b[var9];

         while(var9 > 0) {
            --var9;
            float var8 = this.b[var9];
            --var9;
            var7 = this.b[var9];
            if (var7 < var1) {
               var1 = var7;
            }

            if (var8 < var2) {
               var2 = var8;
            }

            if (var7 > var3) {
               var3 = var7;
            }

            if (var8 > var4) {
               var4 = var8;
            }
         }
      } else {
         var4 = 0.0F;
         var3 = 0.0F;
         var2 = 0.0F;
         var1 = 0.0F;
      }

      return new Float(var1, var2, var3 - var1, var4 - var2);
   }

   public PathIterator getPathIterator(AffineTransform at) {
      return new zb(this, at);
   }

   public PathIterator getPathIterator(AffineTransform at, double flatness) {
      return new FlatteningPathIterator(this.getPathIterator(at), flatness);
   }

   public final int i() {
      return this.e;
   }

   public boolean intersects(double x, double y, double w, double h) {
      return this.m().intersects(x, y, w, h);
   }

   public boolean intersects(Rectangle2D r) {
      return this.intersects(r.getX(), r.getY(), r.getWidth(), r.getHeight());
   }

   public final void a(float var1, float var2) {
      this.n();
      this.a(1, 2, true);
      this.a[this.c++] = 1;
      this.b[this.d++] = var1;
      this.b[this.d++] = var2;
   }

   public final void b(float var1, float var2) {
      this.n();
      if (this.c > 0 && this.a[this.c - 1] == 0) {
         this.b[this.d - 2] = var1;
         this.b[this.d - 1] = var2;
      } else {
         this.a(1, 2, false);
         this.a[this.c++] = 0;
         this.b[this.d++] = var1;
         this.b[this.d++] = var2;
      }

   }

   public final void a(float var1, float var2, float var3, float var4) {
      this.n();
      this.a(1, 4, true);
      this.a[this.c++] = 2;
      this.b[this.d++] = var1;
      this.b[this.d++] = var2;
      this.b[this.d++] = var3;
      this.b[this.d++] = var4;
   }

   public final void a(int var1) {
      if (var1 != 0 && var1 != 1) {
         throw new IllegalArgumentException("winding rule must be WIND_EVEN_ODD or WIND_NON_ZERO");
      } else {
         this.e = var1;
      }
   }

   public final void a(AffineTransform var1) {
      this.a(var1, 0, this.d());
   }

   public final void a(AffineTransform var1, int var2, int var3) {
      this.n();
      var1.transform(this.b, var2, this.b, var2, var3 / 2);
   }

   private final void a(int var1, int var2, boolean var3) {
      if (var3 && this.c == 0) {
         throw new IllegalPathStateException("missing initial moveto in path definition");
      } else {
         int var4 = this.b.length;
         int var5;
         if (this.d + var2 > var4) {
            var5 = var4;
            if (var4 > 1000) {
               var5 = 1000;
            }

            if (var5 < var2) {
               var5 = var2;
            }

            float[] var6 = new float[var4 + var5];
            System.arraycopy(this.b, 0, var6, 0, this.d);
            this.b = var6;
         }

         var4 = this.a.length;
         if (this.c + var1 > var4) {
            var5 = var4;
            if (var4 > 500) {
               var5 = 500;
            }

            if (var5 < var1) {
               var5 = var1;
            }

            byte[] var7 = new byte[var4 + var5];
            System.arraycopy(this.a, 0, var7, 0, this.c);
            this.a = var7;
         }

      }
   }

   public final void j() {
      this.n();
      if (this.c() > 0) {
         byte[] var10000 = this.a();
         int var10001 = this.c() - 1;
         var10000[var10001] = (byte)(var10000[var10001] | 32);
      }

   }

   public final void k() {
      this.n();
      if (this.c() > 0) {
         byte[] var10000 = this.a();
         int var10001 = this.c() - 1;
         var10000[var10001] = (byte)(var10000[var10001] | 16);
      }

   }

   private final void a(int var1, int var2) {
      this.n();
      this.a = new byte[var1];
      this.b = new float[var2 * 2];
      this.c = 0;
      this.d = 0;
   }

   public final void l() {
      this.a(20, 20);
   }
}
